package com.jcark.ui.view

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.constraintlayout.widget.ConstraintLayout
import com.jcark.ui.R
import com.jcark.ui.databinding.LayoutEmptyBinding

/**
 * Description:空布局<br>
 * @author King.Zi<br>
 * @date 2025/02/27<br>
 * Email: 78688689@qq.com
 */
class EmptyView(context: Context?, params: EmptyParams) : ConstraintLayout(context!!) {
    val binding: LayoutEmptyBinding

    init {
        LayoutInflater.from(context).inflate(R.layout.layout_empty, this)
        binding = LayoutEmptyBinding.bind(this)
        layoutParams = ViewGroup.LayoutParams(-1, -1)
        with(params) {
            if (title.isNotEmpty()) {
                binding.tvTitle.visibility = View.VISIBLE
                binding.tvTitle.text = title
            }
            if (image != -1) {
                binding.ivImage.visibility = View.VISIBLE
                binding.ivImage.setImageResource(image)
            }
            if (content.isNotEmpty()) {
                binding.tvContent.visibility = View.VISIBLE
                binding.tvContent.text = content
            }
            if (buttonText.isNotEmpty()) {
                binding.tvButton.visibility = View.VISIBLE
                binding.tvButton.text = buttonText
                binding.tvButton.setOnClickListener {
                    action?.invoke()
                }
            }
        }
    }

    data class EmptyParams(
        val title: String = "",
        val image: Int = -1,
        val content: String = "",
        val buttonText: String = "",
        val action: (() -> Unit)? = null
    )
}
